home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / vbcc-68k-src / machines / amiga68k / libsrc / amigalib / timedelay.c < prev    next >
C/C++ Source or Header  |  1999-01-01  |  1KB  |  42 lines

  1. #include <exec/memory.h>
  2. #include <devices/timer.h>
  3. #include <proto/exec.h>
  4.  
  5. #define NEWLIST(l) ((l)->lh_Head = (struct Node *)&(l)->lh_Tail, \
  6.                     (l)->lh_TailPred = (struct Node *)&(l)->lh_Head)
  7.  
  8. LONG TimeDelay(long unit, unsigned long secs, unsigned long microsecs)
  9. {
  10.   struct PortIO {
  11.     struct timerequest treq;
  12.     struct MsgPort port;
  13.   } *portio;
  14.   long ret=-1;
  15.  
  16.   if ((portio=(struct PortIO *)AllocMem(sizeof(struct PortIO),MEMF_CLEAR|MEMF_PUBLIC)))
  17.   {
  18.     portio->port.mp_Node.ln_Type=NT_MSGPORT;
  19.     if ((BYTE)(portio->port.mp_SigBit=AllocSignal(-1))>=0)
  20.     {
  21.       portio->port.mp_SigTask=FindTask(NULL);
  22.       NEWLIST(&portio->port.mp_MsgList);
  23.  
  24.       portio->treq.tr_node.io_Message.mn_Node.ln_Type=NT_MESSAGE;
  25.       portio->treq.tr_node.io_Message.mn_ReplyPort=&portio->port;
  26.       if (!(OpenDevice(TIMERNAME,unit,&portio->treq.tr_node,0)))
  27.       {
  28.         portio->treq.tr_node.io_Command=TR_ADDREQUEST;
  29.         portio->treq.tr_time.tv_secs=secs;
  30.         portio->treq.tr_time.tv_micro=microsecs;
  31.         if (!DoIO(&portio->treq.tr_node))
  32.           ret=0;
  33.         CloseDevice(&portio->treq.tr_node);
  34.       }
  35.       FreeSignal(portio->port.mp_SigBit);
  36.     }
  37.     FreeMem(portio,sizeof(struct PortIO));
  38.   }
  39.   return ret;
  40. }
  41.  
  42.